<template>
	<view class="navbar">
		<!-- 返回按钮 -->
		<view class="back-btn" @click="onBack">
			<image src="../static/imags/fanhui.png" class="back-icon" />
		</view>
		<!-- 标题 -->
		<view class="title">{{ title }}</view>
	</view>
</template>
<script>
	export default {
		props: {
			title: {
				type: String,
				default: "标题",
			},
		},
		methods: {
			onBack() {
				const pages = getCurrentPages();
				console.log(pages, 66);
				if (pages.length > 1) {
					uni.navigateBack({ delta: 1 });
				} else {
					uni.switchTab({ url: '/pages/login/index' }); // 跳转到首页或其他页面
				}
				// uni.navigateBack();
			},
		},
	};
</script>
<style scoped>
	.navbar {
		/*  height: 148rpx; */
		height: 176rpx;
		display: flex;
		align-items: center;
		/* 垂直居中 */
		background: #1be820 !important;
		color: white;
		position: fixed;
		/* 固定在顶部 */
		top: 0;
		left: 0;
		width: 100%;
		/* 占满屏幕宽度 */
		z-index: 10;
		/* 确保层级高于其他内容 */
	}

	.back-btn {
		width: 96rpx;
		height: 48rpx;
		display: flex;
		align-items: left;
		justify-content: center;
		margin-top: 70rpx;
	}

	.back-icon {
		width: 48rpx;
		height: 48rpx;
	}

	.title {
		flex: 1;
		/* 占据剩余空间 */
		font-size: 40rpx;
		font-weight: bold;
		text-align: center;
		/* 水平居中 */
		margin-right: 68rpx;
		/* 确保标题居中对齐 */
		font-size: 36rpx;
		margin-top: 70rpx;
	}
</style>